﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ALDIOrganizer.Properties;

namespace ALDIOrganizer
{
    public partial class UserAccountInfo : Form
    {
        public UserAccountInfo()
        {
            InitializeComponent();

            lblViewStaff.Tag = lblDescripVS;
            lblEditStaff.Tag = lblDescripES;
            lblDeleteStaff.Tag = lblDescripDS;
            lblEditContracts.Tag = lblDescripEC;
            lblEditHolidays.Tag = lblDescripEH;
            lblEditPastHolidays.Tag = lblDescripEPH;
            lblViewRequests.Tag = lblDescripVR;
            lblEditRequests.Tag = lblDescripER;
            lblEditRotas.Tag = lblDescripERt;
            lblEditPastRotas.Tag = lblDescripEPRt;
            lblEditTemplates.Tag = lblDescripET;
            lblSaveFiles.Tag = lblDescripSF;

            ReadValues();
        }

        private static string YouCanOrNot(bool pState)
        {
            return pState ?
                Resources.FORM_USERACCOUNTINFO_PRIVILEGE_On :
                Resources.FORM_USERACCOUNTINFO_PRIVILEGE_Off;
        }

        private static void setLabel(Label pLabel, bool pState)
        {
            pLabel.Text = YouCanOrNot(pState);
            pLabel.ForeColor = pState ?
                Settings.Default.FORM_USERACCOUNT_PrivilegeOn :
                Settings.Default.FORM_USERACCOUNT_Privilege_Off;
            var _description = pLabel.Tag as Label;
            if (_description == null)
            {
                return;
            }
            _description.Left = pLabel.Right;
        }

        private void ReadValues()
        {
            #region groupbox Identity
            lblLoginValue.Text = Program.Logged.Login;
            if (!Program.Logged.NotAnEmployee)
            {
                lblRealNameValue.Text = SQLiteAccess.GetEmployeeFullName(Program.Logged.ID);
            }
            #endregion

            #region groupbox Privileges
            setLabel(lblViewStaff, Program.Logged.CanViewStaff);
            setLabel(lblEditStaff, Program.Logged.CanEditStaff);
            setLabel(lblDeleteStaff, Program.Logged.CanDeleteStaff);
            setLabel(lblEditContracts, Program.Logged.CanEditContracts);
            setLabel(lblEditHolidays, Program.Logged.CanEditHolidays);
            setLabel(lblEditPastHolidays, Program.Logged.CanEditPastHolidays);
            setLabel(lblViewRequests, Program.Logged.CanViewRequests);
            setLabel(lblEditRequests, Program.Logged.CanEditRequests);
            setLabel(lblEditRotas, Program.Logged.CanEditRota(DateTime.Now.Date));
            setLabel(lblEditPastRotas, Program.Logged.CanEditRota(default(DateTime)));
            setLabel(lblEditTemplates, Program.Logged.CanEditTemplates);
            setLabel(lblSaveFiles, Program.Logged.CanSaveDatafiles);            
            #endregion
        }


    }
}
